package com.toman.ui.work.management;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.itheima.pulltorefreshlib.PullToRefreshBase;
import com.itheima.pulltorefreshlib.PullToRefreshScrollView;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;
import com.lzy.okhttputils.request.GetRequest;
import com.toman.Enum.BaseEnum;
import com.toman.Enum.NetworkEnum;
import com.toman.Enum.PermEnum;
import com.toman.Interfaces.NewBaseUrl;
import com.toman.JavaBean.FeedbackEntity;
import com.toman.JavaBean.StaticsCount;
import com.toman.R;
import com.toman.Util.ActionCallback;
import com.toman.Util.BaseNetUtil;
import com.toman.Util.DialogUtils;
import com.toman.Util.IntentUtils;
import com.toman.Util.JsonExcludeNull;
import com.toman.Util.PermissonUtils;
import com.toman.Util.StringUtils;
import com.toman.Util.ToastUtil;
import com.toman.Util.ViewUtil;
import com.toman.bean.DialogBean;
import com.toman.toolbar.ToolBarActivity;
import com.toman.widget.ClearEditText;
import com.toman.widget.callback.StringLoadingCallback;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Request;
import okhttp3.Response;

public class ProblemFeedbackActivity extends ToolBarActivity {
    CommonAdapter<FeedbackEntity> adapter;
    private List<FeedbackEntity> list = new ArrayList<>();
    @BindView(R.id.et_search)
    ClearEditText etSearch;
    @BindView(R.id.tv_select)
    TextView tvSelect;
    @BindView(R.id.fl_et)
    RelativeLayout flEt;
    @BindView(R.id.tv_select0)
    TextView tvSelect0;
    @BindView(R.id.iv_select0)
    ImageView ivSelect0;
    @BindView(R.id.rl_select0)
    RelativeLayout rlSelect0;
    @BindView(R.id.tv_select1)
    TextView tvSelect1;
    @BindView(R.id.iv_select1)
    ImageView ivSelect1;
    @BindView(R.id.rl_select1)
    RelativeLayout rlSelect1;
    @BindView(R.id.tv_select2)
    TextView tvSelect2;
    @BindView(R.id.iv_select2)
    ImageView ivSelect2;
    @BindView(R.id.rl_select2)
    RelativeLayout rlSelect2;
    @BindView(R.id.tv_select3)
    TextView tvSelect3;
    @BindView(R.id.iv_select3)
    ImageView ivSelect3;
    @BindView(R.id.rl_select3)
    RelativeLayout rlSelect3;
    @BindView(R.id.ll_base)
    LinearLayout llBase;
    @BindView(R.id.cb_muti)
    CheckBox cbMuti;
    @BindView(R.id.btn_muti)
    Button btnMuti;
    @BindView(R.id.rl_muti)
    RelativeLayout rlMuti;
    @BindView(R.id.lv)
    RecyclerView lv;
    @BindView(R.id.mPullToRefreshScrollView)
    PullToRefreshScrollView mPullToRefreshScrollView;
    @BindView(R.id.mMangeNodata)
    TextView mMangeNodata;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_problem_feedback);
        ButterKnife.bind(this);
        initToolBar(BaseEnum.FEEDBACK.name);
        initView();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (!StringUtils.isEmpty(getIntent().getStringExtra("status"))){
            p_id=(getIntent().getStringExtra("etSearch"));
            setStatus(getIntent().getStringExtra("status"));
        } else {
            customer(1, 1, etSearch.getText().toString());
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        rlMuti.setVisibility(View.GONE);
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.toolbar_add, menu);
        MenuItem menuItem = menu.findItem(R.id.menu_add);

        if (!PermissonUtils.contains(this, BaseEnum.FEEDBACK.has(PermEnum.ADD))) {
            menuItem.setVisible(false);
        }

        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.menu_add:
//                        Bundle bundle = new Bundle();
//                        bundle.putString("id", getIntent().getStringExtra("id"));
                        IntentUtils.startActivity(ProblemFeedbackActivity.this, ProblemFeedbackAddActivity.class);

                        break;


                }
                return false;
            }
        });

        return true;
    }

    private void initView() {
        baseEnum=BaseEnum.FEEDBACK;
//        ViewUtil.permission(getApplicationContext(),BaseEnum.FIRSTINSPECTION.has(PermEnum.CHECK),rlMuti);
        etSearch.setHint("企业名称/问题名称");
        initAdapter();
        cbMuti.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

                for (int i = 0; i < list.size(); i++) {
                    list.get(i).setCheckStatus(b);
                }
                adapter.notifyDataSetChanged();
            }
        });
        adapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                List<FeedbackEntity> beanlist = adapter.getDatas();
                FeedbackEntity bean = beanlist.get(position);
                Bundle bundle = new Bundle();
                bundle.putSerializable("bean", bean);
                bundle.putString("status", bean.getFeedbackStatus());
                IntentUtils.startActivity(ProblemFeedbackActivity.this, ProblemFeedbackInfActivity.class, bundle);
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
        lv.setAdapter(adapter);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) {
        };
        lv.setLayoutManager(linearLayoutManager);
        mPullToRefreshScrollView.setMode(PullToRefreshBase.Mode.BOTH);
        mPullToRefreshScrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {dialog=null;
                dialog=null;
                dialogList.clear();
                p_id=null;

                page = 2;
                customer(1, 1, etSearch.getText().toString().trim());
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {

                customer(page, 2, etSearch.getText().toString().trim());
                page += 1;


            }
        });
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                customer(1, 1, s.toString().trim());

            }
        });
    }


    private void initAdapter() {
        adapter = new CommonAdapter<FeedbackEntity>(this, R.layout.reuse_list_workshop, list) {
            @Override
            protected void convert(ViewHolder holder, FeedbackEntity item, final int position) {
//                holder.setText(R.id.tv_code, item.getSendworkorderEntity().getSendworkCode());
                CheckBox checkBox = holder.getView(R.id.cb_status);
                ImageView iv_status = holder.getView(R.id.iv_status);
                checkBox.setChecked(item.getCheckStatus());
                checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> item.setCheckStatus(isChecked));

                TextView tv_time = holder.getView(R.id.tv_time);
                TextView tv_title7 = holder.getView(R.id.tv_title7);
                TextView tv_man = holder.getView(R.id.tv_content7);
                holder.setText(R.id.tv_code, item.getFeedbackNum());
                holder.getView(R.id.iv_status).setVisibility(View.GONE);
                holder.setText(R.id.tv_title1, "企业名称");
                holder.setText(R.id.tv_content1, item.getCompanyName());
                holder.setText(R.id.tv_title2, "主题");
              TextView tv_content2 = holder.getView(R.id.tv_content2);
              tv_content2.setSingleLine();
              tv_content2.setEllipsize(TextUtils.TruncateAt.END);
                holder.setText(R.id.tv_content2, item.getFeedbackName());
                holder.setText(R.id.tv_title3, "问题类别");
                try {
                    holder.setText(R.id.tv_content3, getResources().getStringArray(R.array.ProblemType)[Integer.parseInt(item.getFeedbackType())]);
                } catch (Resources.NotFoundException e) {
                    e.printStackTrace();
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
                holder.setText(R.id.tv_title4, "问题对象");
                try {
                    holder.setText(R.id.tv_content4, getResources().getStringArray(R.array.ProblemObject)[Integer.parseInt(item.getFeedbackObject())]);
                } catch (Resources.NotFoundException e) {
                    e.printStackTrace();
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
                holder.setText(R.id.tv_title5, "产线名称");
                holder.setText(R.id.tv_content5, item.getBeltlineName());
                holder.setText(R.id.tv_title6, "终端名称");
                holder.setText(R.id.tv_content6, item.getTerminalName());
                holder.getView(R.id.btn_del).setVisibility(View.VISIBLE);
                holder.getView(R.id.btn_del).setOnClickListener(v -> BaseNetUtil.actionDialog(ProblemFeedbackActivity.this, NewBaseUrl.management_feedback_delete, item.getId() + "", token, "删除" + BaseEnum.FEEDBACK.name, () -> customer(1, 1, etSearch.getText().toString())));
//                holder.getView(R.id.btn_check).setOnClickListener(v -> CheckDialog(ProblemFeedbackActivity.this,"首件质检","",item));


                if (item.getFeedbackObject().equals("0")) {
                    holder.getView(R.id.ll_5).setVisibility(View.VISIBLE);
                    holder.getView(R.id.ll_6).setVisibility(View.VISIBLE);
                } else {
                    holder.getView(R.id.ll_5).setVisibility(View.GONE);
                    holder.getView(R.id.ll_6).setVisibility(View.GONE);
                }
                holder.getView(R.id.ll_7).setVisibility(View.VISIBLE);


                if (!PermissonUtils.contains(getApplicationContext(), BaseEnum.COMPANY.has(PermEnum.LOOK))) {
                    holder.getView(R.id.ll_1).setVisibility(View.GONE);
                    TextView title = holder.getView(R.id.tv_title2);
                    title.setTextColor(getResources().getColor(R.color.button_blue));
                    title.setTextSize(16);
                    TextView name = holder.getView(R.id.tv_content2);
                    name.setTextColor(getResources().getColor(R.color.button_blue));
                    name.setTextSize(16);

                }

                iv_status.setVisibility(View.GONE);
                switch (item.getFeedbackStatus()) {
                    case "0":
                        tv_time.setText(item.getCreateTime());
                        tv_title7.setText("填单人员");
                        tv_man.setText(item.getCreateUserName());
                        Button button = holder.getView(R.id.btn_check);
                        button.setText("分配");
                        button.setOnClickListener(v -> {
                            Bundle bundle = new Bundle();
                            bundle.putSerializable("bean", item);
                            IntentUtils.startActivity(ProblemFeedbackActivity.this, ProblemFeedbackDistributionActivity.class, bundle);
                        });

                        ViewUtil.permissionNew(getApplicationContext(),BaseEnum.FEEDBACK.has(PermEnum.DISTRIBUTION),button);
                        checkBox.setVisibility(View.GONE);
                        break;

                    case "1":
                        tv_time.setText(item.getDistributionTime());
                        tv_title7.setText("分配人员");
                        tv_man.setText(item.getDistributionUserName());
                        button = holder.getView(R.id.btn_check);
                        button.setText("处理");
//                        ViewUtil.permissionNew(getApplicationContext(),BaseEnum.FEEDBACK.has(PermEnum.DEALWITH),button);
                        if (item.getHandleUserId().equals((String) PermissonUtils.get(getApplicationContext(), "userid", ""))) {
                            button.setVisibility(View.VISIBLE);
                        }
                        else {
                            button.setVisibility(View.GONE);
                        }


                        button.setOnClickListener(v -> {
                            Bundle bundle = new Bundle();
                            bundle.putSerializable("bean", item);
                            IntentUtils.startActivity(ProblemFeedbackActivity.this, ProblemFeedbackProgressActivity.class, bundle);
                        });
                        break;

                    case "2":
                        tv_time.setText(item.getProcessingEndTime());
                        tv_title7.setText("处理人员");
                        tv_man.setText(item.getHandleUserName());
                        button = holder.getView(R.id.btn_check);
                        button.setText("审核");
                        ViewUtil.permissionNew(getApplicationContext(),BaseEnum.FEEDBACK.has(PermEnum.CHECK),button);
                        checkBox.setVisibility(View.VISIBLE);
                        button.setOnClickListener(v -> BaseNetUtil.actionDialog(ProblemFeedbackActivity.this, NewBaseUrl.management_feedback_audit, item.getId() + "", token, "审核" + BaseEnum.FEEDBACK.name, () -> customer(1, 1, etSearch.getText().toString())));

                        break;

                    case "3":
                        iv_status.setVisibility(View.VISIBLE);
                        button = holder.getView(R.id.btn_check);

//                        未归档
                        if (item.getFileStatus().equals("0")) {
                            button.setVisibility(View.VISIBLE);
                            iv_status.setImageResource(R.mipmap.icon_wgd);
                            button = holder.getView(R.id.btn_check);
                            button.setText("归档");
                            button.setOnClickListener(v -> BaseNetUtil.actionDialog(ProblemFeedbackActivity.this, NewBaseUrl.management_feedback_classify, item.getId() + "", token, "归档" + BaseEnum.FEEDBACK.name, () -> customer(1, 1, etSearch.getText().toString())));
                            checkBox.setVisibility(View.VISIBLE);
                            ViewUtil.permissionNew(getApplicationContext(),BaseEnum.FEEDBACK.has(PermEnum.ARCHIVE),button);

                        }
//                        已归档
                        else {
                            button.setVisibility(View.GONE);
                            iv_status.setImageResource(R.mipmap.icon_ygd);
                            checkBox.setVisibility(View.GONE);
                        }
                        tv_time.setText(item.getAuditTime());
                        tv_title7.setText("审核人员");
                        tv_man.setText(item.getAuditUserName());

                        break;
                }


            }
        };
    }
    private String getArchiveList() {
        StringBuilder stringBuffer = new StringBuilder();

        for (int i = 0; i < list.size(); i++) {

            if (list.get(i).getCheckStatus()) {
                if (list.get(i).getFileStatus().equals("0")) {
                    if (stringBuffer.length() <= 0) {
                        stringBuffer.append(list.get(i).getId());
                    } else {
                        stringBuffer.append(",").append(list.get(i).getId());
                    }
                }
            }

        }
        if (stringBuffer.length() <= 0) {
            return null;
        } else {
            return stringBuffer.toString();
        }

    }

    public void customer(Integer page, final Integer type, String search) {
        if (dialog != null) {
            dialog.dismiss();
        }
        GetRequest params = OkHttpUtils
                .get(NewBaseUrl.management_feedback_list)
                .params("token", token)
                .params("key", search)
                .params("limit", NewBaseUrl.num)
                .params("page", page.toString())
                .params("id",p_id)
                .params("feedbackStatus", status);
        for (DialogBean bean: dialogList){
            params.params(bean.getSubmitName(),bean.getResult());
        }
                params.execute(new StringLoadingCallback(this,mPullToRefreshScrollView,search) {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", getClass() + result);
                        if (type == 1) {
                            list.clear();
                        }
                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,getApplicationContext());
                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");

                            List<FeedbackEntity> jsonArray = new ArrayList<FeedbackEntity>(JsonExcludeNull.parseArrayExcludeNull(Jpage.getString("list"), FeedbackEntity.class));
                            list.addAll(jsonArray);

                            if (list.size() == 0) {
                                mMangeNodata.setVisibility(View.VISIBLE);
                            } else {
                                mMangeNodata.setVisibility(View.GONE);
                            }
                            adapter.notifyDataSetChanged();
                            StaticsCount count = JSON.parseObject(Jpage.getString("staticsCount"), new TypeReference<StaticsCount>() {
                            });
                            tvSelect0.setText("待分配(" + count.getCount0() + ")");
                            tvSelect1.setText("待处理(" + count.getCount1() + ")");
                            tvSelect2.setText("待审核(" + count.getCount2() + ")");
                            tvSelect3.setText("已完成(" + count.getCount3() + ")");
setCbMuti();
                        } else {
                            ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
                        }

                        mPullToRefreshScrollView.onRefreshComplete();
                    }
                });
    }

    private void setStatus(String status) {
        this.status = status;
        cbMuti.setChecked(false);
        switch (status) {
            case "0":

                tvSelect0.setTextColor(getResources().getColor(R.color.button_blue));
                tvSelect1.setTextColor(getResources().getColor(R.color.black33));
                tvSelect2.setTextColor(getResources().getColor(R.color.black33));
                tvSelect3.setTextColor(getResources().getColor(R.color.black33));
                ivSelect0.setBackgroundColor(getResources().getColor(R.color.button_blue));
                ivSelect1.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect2.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect3.setBackgroundColor(getResources().getColor(R.color.white));
                customer(1, 1, etSearch.getText().toString());
                break;
            case "1":


                tvSelect1.setTextColor(getResources().getColor(R.color.button_blue));
                tvSelect2.setTextColor(getResources().getColor(R.color.black33));
                tvSelect3.setTextColor(getResources().getColor(R.color.black33));
                tvSelect0.setTextColor(getResources().getColor(R.color.black33));
                ivSelect1.setBackgroundColor(getResources().getColor(R.color.button_blue));
                ivSelect2.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect3.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect0.setBackgroundColor(getResources().getColor(R.color.white));

                customer(1, 1, etSearch.getText().toString());

                break;
            case "2":


                tvSelect2.setTextColor(getResources().getColor(R.color.button_blue));
                tvSelect1.setTextColor(getResources().getColor(R.color.black33));
                tvSelect0.setTextColor(getResources().getColor(R.color.black33));
                tvSelect3.setTextColor(getResources().getColor(R.color.black33));
                ivSelect2.setBackgroundColor(getResources().getColor(R.color.button_blue));
                ivSelect1.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect0.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect3.setBackgroundColor(getResources().getColor(R.color.white));

                customer(1, 1, etSearch.getText().toString());

                break;
            case "3":

                tvSelect3.setTextColor(getResources().getColor(R.color.button_blue));
                tvSelect1.setTextColor(getResources().getColor(R.color.black33));
                tvSelect0.setTextColor(getResources().getColor(R.color.black33));
                tvSelect2.setTextColor(getResources().getColor(R.color.black33));
                ivSelect3.setBackgroundColor(getResources().getColor(R.color.button_blue));
                ivSelect1.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect0.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect2.setBackgroundColor(getResources().getColor(R.color.white));
                customer(1, 1, etSearch.getText().toString());

                break;

        }
    }




    @OnClick({R.id.rl_select0, R.id.rl_select1, R.id.rl_select2, R.id.rl_select3, R.id.btn_muti})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_select0:
                setStatus("0");
                break;
            case R.id.rl_select1:
                setStatus("1");
                break;
            case R.id.rl_select2:
                setStatus("2");
                break;
            case R.id.rl_select3:
                setStatus("3");
                break;
            case R.id.btn_muti:
                switch (status) {
                    case "2":
                        if (ViewUtil.getMutiCheck(list) == null) {
                            ToastUtil.makeText(getApplicationContext(), "请至少选中一个选项");
                        } else {
                            DialogUtils.mutiCheckDialog(this, BaseEnum.FEEDBACK.name, "审核", NewBaseUrl.management_feedback_audit, ViewUtil.getMutiCheck(list), new ActionCallback() {
                                @Override
                                public void run() {
                                    customer(1, 1, etSearch.getText().toString());
                                }
                            });
                        }
                        break;

                    case "3":
                        if (getArchiveList() == null) {
                            ToastUtil.makeText(getApplicationContext(), "请至少选中一个可归档选项");}
else {
                            DialogUtils.mutiCheckDialog(this, BaseEnum.FEEDBACK.name, "归档", NewBaseUrl.management_feedback_classify, getArchiveList(), new ActionCallback() {
                                @Override
                                public void run() {
                                    customer(1, 1, etSearch.getText().toString());
                                }
                            });
                        }
                            break;
                        }


                        break;
                }
        }

    private void setCbMuti() {
        cbMuti.setChecked(false);

        switch (status) {

            case "2":
                btnMuti.setText("一键审核");
                if (PermissonUtils.contains(this, baseEnum.has(PermEnum.CHECK)) && list.size() != 0) {
                    rlMuti.setVisibility(View.VISIBLE);
                } else {
                    rlMuti.setVisibility(View.GONE);
                }

                break;
            case "3":
                btnMuti.setText("一键归档");
                if (PermissonUtils.contains(this, baseEnum.has(PermEnum.ARCHIVE)) && list.size() != 0) {
                    rlMuti.setVisibility(View.VISIBLE);
                } else {
                    rlMuti.setVisibility(View.GONE);
                }

                break;
            default:
                rlMuti.setVisibility(View.GONE);
        }

    }


    @OnClick(R.id.tv_select)
    public void onViewClicked() {
        showDialog();

    }
    public void showDialog() {
        if (dialog == null) {
            dialogList.clear();
            if (mCompanyId=="1") {
                dialogList.add(new DialogBean("companyId", "企业名称", 1, BaseNetUtil.base(this, NetworkEnum.COMPANY, mCompanyId)));
            }
//            dialogList.add( new DialogBean("departmentId","部门名称", 1, BaseNetUtil.base(this, NetworkEnum.DEP, mCompanyId)));
            dialogList.add( new DialogBean("feedbackType","问题类别", 1, getResources().getStringArray(R.array.ProblemType)));
            dialogList.add( new DialogBean("feedbackObject","问题对象", 1, getResources().getStringArray(R.array.ProblemObject)));



            dialog = DialogUtils.selectNewDialog(this, dialogList, new ActionCallback() {
                @Override
                public void run() {
                    customer(1, 1,"");
                    dialog.dismiss();

                }
            });
            dialog.show();
        } else {
            dialog.show();
        }
    }
}
